/**
 * Copyright (C) 2010 D. Zoller, M. Richter, M. Blumenstein & W. Biller
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.siafu.rest;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;

import com.googlecode.siafu.rest.commands.FindNearbyAgentsCommand;
import com.googlecode.siafu.rest.commands.FindNearbyPlacesCommand;
import com.googlecode.siafu.rest.commands.GetAgentCommand;
import com.googlecode.siafu.rest.commands.GetTrackableCommand;
import com.googlecode.siafu.rest.commands.UpdateAgentCommand;
import com.googlecode.siafu.rest.commands.UpdateTrackableCommand;
import com.googlecode.siafu.rest.model.Agent;
import com.googlecode.siafu.rest.model.Place;


/** 
 * @author W. Biller
 * @author D. Zoller
 * @version $Id: AgentsResource.java,v 1.9 2010-06-14 07:57:55 nosebrain Exp $
 */
@Path("/agents")
public class AgentsResource extends TrackableResource<Agent> {

	@Override
	protected GetTrackableCommand<Agent> getGetCommand(String name) {
		return new GetAgentCommand(name);
	}

	@Override
	protected UpdateTrackableCommand<Agent> getUpdateCommand(Agent trackable) {
		return new UpdateAgentCommand(trackable);
	}
	
	/**
	 * GET method to retrieve all nearby agents of the specified agent
	 * 
	 * @param name (PathParam)
	 * @param distance (QueryParam)
	 * @return a list of all nearby agents (in distance)
	 */
	@Path("/{name}/nearbyAgents")
	@GET
	public List<Agent> getNearbyAgents(@PathParam("name") String name, @QueryParam("distance") int distance) {
		return new FindNearbyAgentsCommand(name, distance).execute();
	}
	
	/**
	 * GET method to retrieve all nearby places of the specified agent
	 * 
	 * @param name
	 * @param distance
	 * @return a list of all nearby places (in distance)
	 */
	@Path("/{name}/nearbyPlaces")
	@GET
	public List<Place> getNearbyPlaces(@PathParam("name") String name, @QueryParam("distance") int distance) {
		return new FindNearbyPlacesCommand(name, distance).execute();
	}
}
